﻿using DotNetCasClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace CASClient.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var user = HttpContext.User.Identity.Name;
            return View();
        }
        public ActionResult NotAuthorized()
        {
            return Content("NotAuthorized!");
        }
        public ActionResult CookiesRequired()
        {
            return Content("CookiesRequired!");
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
        [AllowAnonymous]
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();
            //CasAuthentication.SingleSignOut();
            //CasAuthentication.RedirectToLoginPage();

            //var port = Request.Url.Port == 80 ? "" : ":" + Request.Url.Port;
            //var xurl = "http://" + Request.Url.Host + port;

            var url = CasAuthentication.CasServerUrlPrefix + "logout?service=" + HttpUtility.UrlEncode(CasAuthentication.ServerName);
            
            return Redirect(url);
        }
    }
}